; $VER: FinalWriter-030_Install 1.19 (11.2.97)

(set version "5.0")

(onerror (exit (quiet)))

(message
	"\n\nFinalWriter " version " '030"
	"\nCopyright 1995-96 Martin Berndt"
	"\n\n\n!!! This Patch is SHAREWARE !!!"
	"\n\nPlease read the \"ReadMe.txt\" file."
)

(set @default-dest
	(askdir
		(prompt "Where is your FinalWriter Drawer?")
		(help @askfile-help)
		(default "SYS:FinalWriter")
		(newpath)
	)
)

(set language
	(askchoice
		(prompt "Select your version")
		(help @askchoice-help)
		(choices "US1  5.0   7-Jun-96 (American English)"
			 "US2  5.03 28-Jun-96 (American English)"
			 "US3  5.04  8-Jul-96 (American English)"
			 "US4  5.06  9-Oct-96 (American English)"
			 "GB1  5.04  8-Jul-96 (British English)"
			 "GB2  5.05  3-Aug-96 (British English)"
			 "GER1 5.05  3-Aug-96 (German)"
			 "GER2 5.06  9-Oct-96 (German)")
	)
)

(set backup
	(askoptions
		(prompt "Options")
		(help @askoptions-help)
		(choices "Create Backup Files")
	)
)

(set n 0)
(set percent 0)

(while (set name (select n "FinalWriter" "swpost.library" "swshell.library"
			   "cachemap.library" "qfont.library" "")) (
	(set n (+ n 1))
	(complete percent)
	(if (= n 1)
		(set file name)
		(set file ("FWLibs/%s" name))
	)
	(set newfile (tackon @default-dest file))
	(set oldfile (cat newfile ".bak"))
	(if (= (exists newfile) 0)
		(abort name " not found!")
	)
	(rename newfile oldfile)
	(if (< n 4) (
                (if (= n 1) (
                        (set name (cat name (select language "US1" "US2" "US3" "US4" "GB1" "GB2" "GER1" "GER2")))
                ))
		(working "\n\nPatching\n" newfile)
		(if (<> (run ("spatch \"-o%s\" \"-p%s.pch\" \"%s\"" newfile name oldfile)) 0) (
			(rename oldfile newfile)
			(abort "Wrong Version!")
		))
		(set percent (+ percent 30))
	) (
		(copyfiles
			(prompt "Copying " name)
			(help @copyfiles-help)
			(source name)
			(dest (tackon @default-dest "FWLibs"))
			(optional "force" "askuser")
		)
		(set percent (+ percent 5))
	))
	(if (= backup 0) (delete oldfile))
))
